$.ajax({
	url: 'userList',
	type: 'POST',
	data: {
		companyId: $.Cookie("companyId"),
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
		index: 0,
		page: 10
	},
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == 0) {
			$.each(data.result.userList, function(i, value) {
				var nDate = new Date(value.lastModifyTime); //直接将毫秒数当参数传进去。
				var month = nDate.getMonth() + 1;
				var year = nDate.getFullYear() + '-' + month + '-' + nDate.getDate() + " " + nDate.getHours() + ':' + nDate.getMinutes() + ':' + nDate.getSeconds();
				var error_tpl;
				if(i % 2 == 0) {
					if(value.roleId == 1) {
						error_tpl = '<div class="userManagement_content_contenta"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" />	 <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
					} else {
						error_tpl = '<div class="userManagement_content_contenta"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" /><div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
					}
				} else {
					if(value.roleId == 1) {
						error_tpl = '<div class="userManagement_content_content"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" />	  <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
					} else {
						error_tpl = '<div class="userManagement_content_content"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" /> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
					}
				}
				$(".pageTool").append(error_tpl);
				ticklength = data.result.userList.length;
				idtick.push(value.id)
			});

			$('.pageToola').Paging({
				pagesize: 10,
				count: data.result.count,
				toolbar: true,
				callback: function(page, size, count) {
					$(".pageTool").html("")
					$.ajax({
						url: 'paramTypeList',
						type: 'POST',
						data: {
							session: $.Cookie("session"),
							userId: $.Cookie("userId"),
							companyId: $.Cookie("companyId"),
							index: page - 1,
							page: 10
						},
						dataType: 'json',
						success: function(data) {
							if(data.errorCode == 0) {
								$.each(data.result.paramTypeList, function(i, value) {
									var nDate = new Date(value.lastModifyTime); //直接将毫秒数当参数传进去。
									var month = nDate.getMonth() + 1;
									var year = nDate.getFullYear() + '-' + month + '-' + nDate.getDate() + " " + nDate.getHours() + ':' + nDate.getMinutes() + ':' + nDate.getSeconds();
									var error_tpl;
									if(i % 2 == 0) {
										if(value.roleId == 1) {
											error_tpl = '<div class="userManagement_content_contenta"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" />	 <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
										} else {
											error_tpl = '<div class="userManagement_content_contenta"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" /><div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
										}
									} else {
										if(value.roleId == 1) {
											error_tpl = '<div class="userManagement_content_content"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" />	  <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
										} else {
											error_tpl = '<div class="userManagement_content_content"> <div onclick="checkInputA(this)" class="content_input_b" id="' + value.id + '"><input style="display:none;" value="' + value.roleId + '"  id="role_' + value.id + '" /> <div id="tick_' + value.id + '" class="tick">√</div> </div> <div class="userManagement_one">' + value.userCode + '</div> <div class="userManagement_one">' + value.userName + '</div> <div class="userManagement_two">' + value.orgName + '</div> <div class="userManagement_three ">' + value.roleNames + '</div> <div class="manage_content_header_div">' + value.email + '</div> <div class="manage_content_header_div">' + value.phone + '</div> <div class="userManagement_one">' + value.lastModifyUser + '</div> <div class="manage_content_header_div">' + year + '</div>  </div>'
										}
									}
									$(".pageTool").append(error_tpl);
									ticklength = data.result.userList.length;
									idtick.push(value.id)
								});
							} else if(data.errorCode == -6) {
								alert("登录超时！")
								top.location.href = 'index.jsp';
							}
						},
						error: function(err) {
							alert("连接服务器失败！请重新提交！")
			top.location.href = 'index.jsp';
						}
					});
				}

			})
		} else if(data.errorCode == -6) {
			alert("登录超时！")
			top.location.href = 'index.jsp';

		}

	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';
		
	}
});

function backDeviceGroup() {
	window.location.href = 'userManagementAdd.jsp';

}
var ticklength;
var idtick = []; //			全体打钩
function checkInput() {
	var tick = $(".tick").css("display");
	if(tick == "none") {
		$(".tick").show();
		tickId = ticklength;
		tickaId = somearray[0];
		somearray = idtick;
	} else if(tick == "block") {
		$(".tick").hide();
		$(".tick").hide();
		$(".tick_block ").hide();
		tickId = 0;
		somearray = [];
		tickaId = somearray[0];
	}
}
//			单独打钩
var tickId = 0;
var tickaId = '';
var somearray = []
var idRole;
var idRoleSome = [];

function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

function checkInputA(data) {
	var ticka = "tick_" + data.id
	var tickBlock = document.getElementById(ticka);
	idRole = "role_" + data.id
	idRole = document.getElementById(idRole).value;
	if(tickBlock.style.display == "block") {
		tickBlock.style.display = "none";
		removeByValue(somearray, data.id);
		removeByValue(idRoleSome, idRole);
		tickId = tickId - 1;
		idRole = idRoleSome;
		tickaId = somearray[0];
	} else if(tickBlock.style.display == "" || tickBlock.style.display == "none") {
		tickBlock.style.display = "block";
		removeByValue(somearray, data.id);
		removeByValue(idRoleSome, idRole);
		idRoleSome.push(idRole);
		somearray.push(data.id);
		tickaId = somearray[0];
		tickId = tickId + 1;
		idRole = idRoleSome;
	}

}

$(".device_edit").click(function() {
	if(tickId == 0) {
		alert("请选择你要编辑的记录！")
	} else if(tickId == 1) {

		var superRoleId = sessionStorage.getItem("superRoleId");
		if(superRoleId == 1) {
			sessionStorage.setItem("tickId", tickId);
			sessionStorage.setItem("tickaId", tickaId);
			window.location.href = 'userManagementAmend.jsp';
		} else {
			if(idRole == 1) {
				alert("权限不足无法编辑")
			} else {
				sessionStorage.setItem("tickId", tickId);
				sessionStorage.setItem("tickaId", tickaId);
				window.location.href = 'userManagementAmend.jsp';
			}
		}

	} else if(tickId > 1) {
		alert("一次只能编辑一条记录！")
	}
})

$(".device_delect").click(function() {
	if(tickId == 0) {
		alert("请选择你要删除的记录！")
	} else if(tickId == 1) {
		if($.Cookie("userId") == tickaId) {
			alert("请勿删除自己！")
		} else {
			var superRoleId = sessionStorage.getItem("superRoleId");
			if(superRoleId == 1) {
				$.ajax({
					url: 'userOperation',
					type: 'POST',
					data: {
						companyId: $.Cookie("companyId"),
						session: $.Cookie("session"),
						userId: $.Cookie("userId"),
						flag: "1",
						uId: tickaId,
					},
					dataType: 'json',
					success: function(data) {
						if(data.errorCode == 0) {
							window.location.href = 'userManagement.jsp';
						} else if(data.errorCode == -6) {
							alert("登录超时！");
							top.location.href = 'index.jsp';
						}
					},
					error: function(err) {
						alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';
						
					}
				});
			} else {
				if(idRole == 1) {
					alert("权限不足无法删除")
				} else {
					$.ajax({
						url: 'userOperation',
						type: 'POST',
						data: {
							companyId: $.Cookie("companyId"),
							session: $.Cookie("session"),
							userId: $.Cookie("userId"),
							flag: "1",
							uId: tickaId,
						},
						dataType: 'json',
						success: function(data) {
							if(data.errorCode == 0) {
								window.location.href = 'userManagement.jsp';
							} else if(data.errorCode == -6) {
								alert("登录超时！")
								top.location.href = 'index.jsp';
							}

						},
						error: function(err) {
							alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';
							
						}
					});
				}
			}
		}

	} else if(tickId > 1) {
		alert("一次只能编辑一条记录！")
	}
})

autodivheight();
function autodivheight() { //函数：获取尺寸
	//获取浏览器窗口高度
	var winHeight = 0;
	if(window.innerHeight)
		winHeight = window.innerHeight;
	else if((document.body) && (document.body.clientHeight))
		winHeight = document.body.clientHeight;
	//通过深入Document内部对body进行检测，获取浏览器窗口高度
	if(document.documentElement && document.documentElement.clientHeight)
		winHeight = document.documentElement.clientHeight;
	//DIV高度为浏览器窗口的高度
		
	
	a = winHeight - 180;
	if(a < 0) {
		a = 0
		$(".pageTool").css("height", a);
//		$(".pageTool").css("min-height", 410);

	} else {
		$(".pageTool").css("height", a);
//		$(".pageTool").css("min-height", 410);
		
	}

}
window.onresize = autodivheight; //浏览器窗口发生变化时同时变化DIV高度